package com.it.selfAfter.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsAutoIncrement;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsKey;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Date;

/**
 * @Author: Coke
 * @TIMESTAMP: 2023/05/28/10:28
 * @注释: 作品类型初始数据
 **/

@Data
@Entity
@TableName ("production_type")
@Table (name = "production_type", comment = "作品类型初始数据")//设置表名  注释
public class ProductionType {
    
    private static final long serialVersionUID = 9435278593475933L;
    
    @IsAutoIncrement   //自增
    @IsKey             //主键
    @TableId ( value = "id", type = IdType.AUTO)
    @Id
    @Column (comment = "ID")//字段注释
    private Long id;
    
    
    /**
     * 作品类型
     */
    @Column(name = "p_type",comment = "作品类型", length = 255)
    private String p_type;
    
    
    /**
     * 作品类型 对应值
     */
    @Column(name = "p_value",comment = "作品类型 对应值", length = 255)
    private String p_value;
    
    /**
     * 作品类型 对应编号
     */
    @Column(name = "p_number",comment = "作品类型 对应编号", length = 255)
    private Integer p_number;
    
    /**
     * 创建时间
     */
    
    @Column(name = "create_time", type = MySqlTypeConstant.TIMESTAMP, comment = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date createTime;
    
    /**
     * 修改时间
     */
    @Column(name = "update_time", type = MySqlTypeConstant.TIMESTAMP, comment = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date updateTime;
    
    
    /**
     * 新增数据时自动添加时间
     */
    @PrePersist
    protected void onCreate() {
        createTime = new Date();
    }
    
    /**
     * 更新数据时自动更新时间
     */
    @PreUpdate
    protected void onUpdate() {
        updateTime = new Date();
    }
    
}
